<!doctype html5>
<html>

    <head>
        <title>编辑CSS</title>
        <meta charset="utf-8">
    </head>

    <body>
        <h1>CSS代码段</h1>
        <textarea cols="200" rows="50">

        </textarea>
        <button onclick="save()">确定</button>
    </body>
    <script>
        window.onload=(e)=>{
            window.opener.postMessage('load')
            addEventListener('message',(css)=>{
                document.querySelector('body>textarea').innerHTML=css.data;
            })
        }

        function save() {
            var css = document.querySelector('body>textarea').innerHTML;
            css=css.replace(/&gt;/g,'>');
            var remote = require('electron').remote;
            var dialog = remote.require('electron').dialog;
            var path = dialog.showSaveDialogSync({
                title: '保存主题CSS文件',
                filters: [{
                        name: 'CSS',
                        extensions: ['css']
                    },
                    {
                        name: 'All Files',
                        extensions: ['*']
                    }
                ]
            });
            var fs = require('fs');
            fs.writeFileSync(path, css);
            window.close();
        }
    </script>

</html>